<?php
/**
 * TicketShowing Model
 *
 */
class TicketShowing extends SeatAppModel {

/**
 * Use table
 *
 * @var mixed False or table name
 */
	public $useTable = 'seat_ticket_showing';

/**
 * Display field
 *
 * @var string
 */
	public $displayField = 'name';

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'seat_ticket_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'showtime' => array(
			'datetime' => array(
				'rule' => array('datetime'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'sort' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'enable' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	
	public function getShowingByTikcetId($ticket_id){
		App::import('Model','Seat.SeatTicket');
		$SeatTicketObj = new SeatTicket();
		$SeatTicketObj->recursive = -1;
		$seatTicket = $SeatTicketObj->findByTicketId($ticket_id);
		$seat_ticket_id = $seatTicket['SeatTicket']['id'];
		$ticketShowing = $this->find('all',array(
				'conditions'=>array(
						'TicketShowing.seat_ticket_id'=>$seat_ticket_id,
						'TicketShowing.enable'=>1
				),
				'order'=>'TicketShowing.showtime ASC'
		));
		return $ticketShowing;
	}
}
